package com.controller;

import com.comment.CommentResult;
import com.domain.entity.Indent;
import com.domain.req.AddIndentReq;
import com.domain.req.IndentUpdateReq;
import com.domain.req.ListIndentReq;
import com.domain.req.PageReq;
import com.github.pagehelper.PageInfo;
import com.service.IndentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理 controller
 */
@CrossOrigin//跨越
@RestController
@Slf4j
@RequestMapping("/indent")
public class IndentController {

    @Autowired
    private IndentService indentService;

    @PutMapping("/updateById")
    public CommentResult<Void> updateById(@RequestBody IndentUpdateReq indentUpdateReq) {
        indentService.updateById(indentUpdateReq);
        return CommentResult.success();
    }


    /**
     * 新增订单请求
     */
    @PostMapping("/addIndent")
    public CommentResult<Indent> addIndent(@RequestBody AddIndentReq addIndentReq) {
        Indent indent = indentService.addIndent(addIndentReq);
        return CommentResult.success(indent);
    }

    /**
     * 列表查询
     */
    @GetMapping("/pageList")
    public CommentResult<PageInfo<Indent>> pageList(PageReq pageReq, ListIndentReq listIndentReq) {
        PageInfo<Indent> pageInfo = indentService.list(pageReq, listIndentReq);
        return CommentResult.success(pageInfo);
    }

    /**
     * 根据订单id查询订单信息
     */
    @GetMapping("/getById/{id}")
    public CommentResult<Indent> getById(@PathVariable("id") Integer id) {
        Indent indent = indentService.getById(id);
        return CommentResult.success(indent);
    }

    /**
     * 根据订单id删除待支付状态的订单
     */
    @DeleteMapping("/deleteById/{id}")
    public CommentResult<Void> deleteById(@PathVariable("id") Integer id) {
        indentService.deleteById(id);
        return CommentResult.success();
    }

    /**
     * 发货
     */
    @PutMapping("/shipments/{id}")
    public CommentResult<Void> shipments(@PathVariable("id") Integer id) {
        indentService.shipments(id);
        return CommentResult.success();
    }

    /**
     * 收货
     */
    @PutMapping("/receipt/{id}")
    public CommentResult<Void> receipt(@PathVariable("id") Integer id) {
        indentService.receipt(id);
        return CommentResult.success();
    }

    /**
     * 支付
     */
    @PostMapping("/payIndent/{indentId}")
    public CommentResult<Void> payIndent(@PathVariable("indentId") Integer indentId) {
        indentService.payIndent(indentId);
        return CommentResult.success();
    }

}
